﻿<%@ page language="java" import="java.util.*"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%
String path = request.getContextPath();
String app_version = net.zoneland.greenleaf.GLOBAL.APP_VERSION;
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>		
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=10;IE=9;IE=8;" />	
  		<!-- Title and other stuffs -->
  		<title>后台管理系统</title> 
  		<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  		<script src="<%=path %>/js/greenleaf/jquery-1.8.3.js"></script> <!-- jQuery -->		
  		<script type="text/javascript">
	  		var path = "<%=path %>";
	  		var app_version = "<%=app_version %>";  
  		</script>
 </head>
 <body>
<div id="mainbar" class="mainbar">
 <!-- Page heading -->
	<div class="page-head">
	    <h2 class="pull-left"><i class="icon-home"></i> 系统配置列表</h2>
        <!-- Breadcrumb -->
        <div class="bread-crumb pull-right">
          <a href="javascript:void()"><i class="icon-home"></i> 系统配置管理</a> 
          <!-- Divider -->
          <span class="divider">/</span> 
          <a href="javascript:void()" class="bread-current">系统配置列表</a>
        </div>
        <div class="clearfix"></div>
	</div>
	<!-- Page heading ends -->

	<!-- Matter -->
	<div class="matter">
        <div class="container">
        <!-- 页面的内容开始. -->
        <!-- Table -->
            <div class="row">
              <div class="col-md-12">
                <div class="widget">
                <div class="widget-head">
                  <div class="pull-left">系统配置列表</div>
                  <div class="widget-icons pull-right">
                    	<!-- 这里是标题栏靠右显示内容，如最大最小化按钮 -->
                    	<!-- 在系统配置界面上应该是不能随意添加和删除配置的，请注意上线前删除这些功能按钮 -->
                    	 <button id="btn_sys_config_add" type="button" class="btn btn-success">添加配置</button>
                         <button id="btn_sys_config_delete" type="button" class="btn btn-danger">删除配置</button>
                  </div>  
                  <div class="clearfix"></div>
                </div>
                  <div class="widget-content">
                    <table class="table table-striped table-bordered table-hover">
                      <thead>
                        <tr>
                          <th><input id="sys_config_check_all" class="check-all" type="checkbox" onclick="checkbox_control(this, 'sys_config_checkbox');"/></th>
							<th>配置名称</th>
							<th>配置内容</th>
							<th>排序号</th>
							<th>备注说明</th>
                        </tr>
                      </thead>
                      <tbody id="sys_config_list_tbody"></tbody>
                    </table>
                    <div class="widget-foot">
                        <ul class="pagination pull-right">
                          <div class="pagination" id="sys_config_pagination"></div> <!-- End .pagination -->
                        </ul>                     
                      <div class="clearfix"></div> 
                    </div>
                  </div>
                </div>
              </div>
            </div>
        <!-- 页面的内容结束. -->
        </div>
	</div>
	<!-- Matter ends -->
</div>
<!-- jQuery Flot -->
<script src="<%=path %>/js/greenleaf/actions/sys_config_action.js"></script>
<script type="text/javascript">
	var sys_config_list_currentpage = 1, sys_config_list_pagesize = 20, sys_config_list_maxpage = 1;
	
	$(document).ready(function(){
			get_sys_config_list("first");
			
			$("#btn_sys_config_add").click(function(){
				loadPage( sys_config_info_action.page.add );
			});
			
			$("#btn_sys_config_delete").click(function(){
				delete_sys_config();
			});
			
	});
	
	//查询所有的任务信息列表方法实现
	function get_sys_config_list(page_flag, fn){
		var url = sys_config_info_action.service.list;
		if("first"==page_flag){
			sys_config_list_currentpage = 1;
		}else if("last"==page_flag){
			sys_config_list_currentpage = sys_config_list_maxpage;
		}else if("next"==page_flag){
			if(sys_config_list_currentpage < sys_config_list_maxpage){
				++sys_config_list_currentpage;
			}
		}else if("preview"==page_flag){
			if(sys_config_list_currentpage >1){
				--sys_config_list_currentpage;
			}
		}		
		var paramMap = {};
		paramMap.page = sys_config_list_currentpage;
		paramMap.pagesize = sys_config_list_pagesize;
		var json_data = JSON.stringify(paramMap);
		
		$.ajax({
			  url: url,
			  type : 'post',
			  async : false,
			  data: json_data,
			  contentType: "application/json; charset=utf-8",
			  dataType: "json",
			  success: function(json) {
				  var sys_config_list_html = "";
					sys_config_list_maxpage = json.pagination.totalPage;
					$(json.list).each(function(){
						sys_config_list_html += "<tr>";
		             	sys_config_list_html += "<td><input name=\"sys_config_checkbox\" id=\""+this.id+"\" type=\"checkbox\" /></td>";		             	
		             	sys_config_list_html += "<td><a href='javascript:loadPage(\""+sys_config_info_action.page.edit+"&id="+this.id+"\");' title=\""+this.c_code+"\">"+this.c_code+"</a></td>";
		             	sys_config_list_html += "<td>"+this.c_value+"</td>";
		             	sys_config_list_html += "<td>"+this.c_order+"</td>"; 
		             	sys_config_list_html += "<td>"+this.remark+"</td>";		             	
		            	sys_config_list_html += "</tr>"
					});
					$("#sys_config_list_tbody").html(sys_config_list_html);
					
					var sys_config_pagination_html = "<li><a href=\"javascript:get_sys_config_list('first')\" title=\"First Page\">首页</a></li><li><a href=\"javascript:get_sys_config_list('preview')\" title=\"Previous Page\">上一页</a></li>";
					var count=0;
					for(var i=sys_config_list_currentpage-3; i<=sys_config_list_maxpage && i<sys_config_list_currentpage+7 && count <7; i++){
						if(i > 0){
							if(i==sys_config_list_currentpage-3){
								if(sys_config_list_currentpage > 3){
									sys_config_pagination_html += "...";
									count++;
									continue;
								}
							}
							sys_config_pagination_html += "<li><a href=\"javascript:sys_config_list_currentpage="+i+";get_sys_config_list()\" class=\"number ";
							if(sys_config_list_currentpage == i){
								sys_config_pagination_html += "current";
							}						
							sys_config_pagination_html += " title=\""+i+"\">"+i+"</a></li>";
							count++;
						}
					}
					if(sys_config_list_maxpage>sys_config_list_currentpage+3){
						sys_config_pagination_html += "...";
						sys_config_pagination_html += "<li><a href=\"javascript:sys_config_list_currentpage="+sys_config_list_maxpage+";get_sys_config_list()\" class=\"number ";
						if(sys_config_list_currentpage == sys_config_list_maxpage){
							sys_config_pagination_html += "current";
						}						
						sys_config_pagination_html += " title=\""+sys_config_list_maxpage+"\">"+sys_config_list_maxpage+"</a><li>/";
					}					
					sys_config_pagination_html += "<li><a href=\"javascript:get_sys_config_list('next')\" title=\"Next Page\">下一页</a></li><li><a href=\"javascript:get_sys_config_list('last')\" title=\"Last Page\">末页</a></li>";
					$("#sys_config_pagination").html(sys_config_pagination_html);
					
					if(fn){fn();}
			  }
		});
	}
	
	function delete_sys_config(){
		var ids = checkbox_get_selected_id("sys_config_checkbox");
		if( ids != "" ){
			if( confirm("您确定需要删除这"+ids.split(",").length+"个系统配置信息吗？数据删除后将无法恢复！") ){
				var url = sys_config_info_action.service.delete_muti;
				if(ids!=null && ids!="0" && ids.length>0){
					var paramMap = {};
					paramMap.ids = ids;
					var json_data = JSON.stringify(paramMap);
					
					$.ajax({
						  url: url,
						  type : 'post',
						  async : false,
						  data: json_data,
						  contentType: "application/json; charset=utf-8",
						  dataType: "json",
						  success: function(json) {
							alert(json.message);
							loadPage(sys_config_info_action.page.list);
							if(fn){fn();}
						  }
					});   
				}
			}
		}else{
			alert("您至少需要选择一个系统配置信息才能进行此操作。");
		}
	}
</script>
</body>